﻿using System.Configuration;

namespace CommerceOne.Common.Configs
{
    /// <summary>
    /// 
    /// </summary>
    public class WidgetInstanceSettingsCollection : ConfigurationElementCollection
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public WidgetInstanceSettings this[int index]
        {
            get
            {
                return base.BaseGet(index) as WidgetInstanceSettings;
            }
            set
            {
                if (base.BaseGet(index) != null)
                {
                    base.BaseRemoveAt(index);
                }

                this.BaseAdd(index, value);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected override ConfigurationElement CreateNewElement()
        {
            return new WidgetInstanceSettings();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((WidgetInstanceSettings)element).Name;
        }

        public void AddNewElement(WidgetInstanceSettings widgetInstance)
        {
            this.BaseAdd(widgetInstance);
        }
    }
}